package dao.impl;

import bean.OrderItem;
import dao.BaseDao;
import dao.OrderItemDao;

import java.util.ArrayList;

public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {
    @Override
    public int insert(OrderItem order) {
        String sql = "INSERT INTO `t_order_item` (`order_id`,`product_id`,`buynum`)VALUES(?,?,?)";
        return update(sql,order.getOrder_id(),order.getProduct_id(),order.getBuynum());
    }

    @Override
    public int delete(Integer id) {
        String sql = "DELETE FROM `t_order_item` WHERE `order_id`=?";
        return update(sql,id);
    }

    @Override
    public OrderItem queryById(Integer id) {
        String sql = "SELECT * FROM `t_order_item` WHERE `order_id`=?";
        return queryForOne(OrderItem.class,sql,id);
    }

    @Override
    public ArrayList<OrderItem> queryAll() {
        String sql = "SELECT * FROM `t_order_item`";
        return queryForList(OrderItem.class,sql);
    }
}
